package com.sgb.auction.viewmodule;

import androidx.lifecycle.ViewModel;

import com.sgb.auction.base.BaseApi;
import com.sgb.auction.entity.AuctionRecordEntity;
import com.sgb.auction.entity.RequestBean;
import com.sgb.auction.fragment.MyOfferFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * Time:2021/11/22
 * AUTHOR:F_Q
 * Description:
 */
public class MyOfferModel  extends ViewModel {
    MyOfferFragment fragment;
    private boolean isLastPage;

    public void setActivity(MyOfferFragment myOfferFragment) {
        fragment = myOfferFragment;
    }

    public void getMyOfferList(RequestBean requestBean) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getAuctionRecord(requestBean).enqueue(new ICallBack<BaseEntity<ListResponse<List<AuctionRecordEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<AuctionRecordEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)){
                    isLastPage = data.getData().getCurrentPage() >= data.getData().getTotal();
                    fragment.setMyOfferList(data.getData().getList(),isLastPage);
                }else {
                    MToast.showToast(fragment.getActivity(),data.getMsg());
                }
            }
        });
    }
}
